package com.zutassociation.web.controller.system;

import com.zutassociation.common.core.controller.BaseController;
import com.zutassociation.common.core.domain.AjaxResult;
import com.zutassociation.common.core.page.TableDataInfo;
import com.zutassociation.common.utils.SecurityUtils;
import com.zutassociation.system.domain.Pick;
import com.zutassociation.system.service.PickService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 社联风采 信息操作处理
 *
 * @author 黄玉东
 * @version 1.0
 * @date 2021/3/18 17:30
 */

@RestController
@RequestMapping("/pick")
public class PickController extends BaseController {

    @Autowired
    private PickService pickService;


    /**
     * 获取社联风采列表
     */
//    @PreAuthorize("@ss.hasPermi('system:pick:list')")
    @GetMapping("/list")
    public TableDataInfo list(Pick pick) {
        startPage();
        List<Pick> list = pickService.selectPickList(pick);
        return getDataTable(list);
    }

    /**
     * 获取社联风采列表
     */
//    @PreAuthorize("@ss.hasPermi('system:pick:list')")
    @GetMapping("/listClick")
    public TableDataInfo listClick(Pick pick) {
        startPage();
        List<Pick> list = pickService.selectPickListClick(pick);
        return getDataTable(list);
    }

    /**
     * 根据社联风采编号获取详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:pick:query')")
    @GetMapping(value = "/getUpPick/{pickId}")
    public AjaxResult getUpPick(@PathVariable("pickId") Long pickId) {
        return AjaxResult.success(pickService.selectUpPick(pickId));
    }

    /**
     * 根据社联风采编号获取详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:pick:query')")
    @GetMapping(value = "/getNextPick/{pickId}")
    public AjaxResult getNextPick(@PathVariable("pickId") Long pickId) {
        return AjaxResult.success(pickService.selectNextPick(pickId));
    }

    /**
     * 根据社联风采编号获取详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:pick:query')")
    @GetMapping(value = "/{pickId}")
    public AjaxResult getInfo(@PathVariable("pickId") Long pickId) {
        return AjaxResult.success(pickService.selectPickById(pickId));
    }

    /**
     * 新增社联风采
     */
    @PreAuthorize("@ss.hasPermi('system:pick:add')")
    @PostMapping
    public AjaxResult add(@Validated @RequestBody Pick pick) {
        pick.setCreateBy(SecurityUtils.getUsername());
        return toAjax(pickService.insertPick(pick));
    }

    /**
     * 修改社联风采
     */
    @PreAuthorize("@ss.hasPermi('system:pick:edit')")
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody Pick pick) {
        pick.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(pickService.updatePick(pick));
    }

//    @PreAuthorize("@ss.hasPermi('system:pick:edit')")
    @PutMapping("/updatePickClick")
    public AjaxResult updatePickClick(@Validated @RequestBody Pick pick) {
        return toAjax(pickService.updatePickClick(pick));
    }

    /**
     * 删除社联风采
     */
    @PreAuthorize("@ss.hasPermi('system:pick:remove')")
    @DeleteMapping("/{pickIds}")
    public AjaxResult remove(@PathVariable Long[] pickIds) {
        return toAjax(pickService.deletePickByIds(pickIds));
    }

}
